package com.cskaoyan.day13;

class TestCompute {
    public static void main(String[] args) {
        test1(20D, 2D);//实现类
        System.out.println("--------------------------");
        test2(20D, 2D);//
        System.out.println("--------------------------");
        test3(20D, 2D);

    }

    public static void test1(Double num1, Double num2) {
        ComputeImp computeImp = new ComputeImp();
        System.out.println(computeImp.add(num1, num2));
        System.out.println(computeImp.sub(num1, num2));
        System.out.println(computeImp.mul(num1, num2));
        System.out.println(computeImp.div(num1, num2));
    }

    public static void test2(Double num1, Double num2) {
        Computer.CPU cpu = new Computer().new CPU();
        System.out.println(cpu.add(num1, num2));
        System.out.println(cpu.sub(num1, num2));
        System.out.println(cpu.mul(num1, num2));
        System.out.println(cpu.div(num1, num2));
    }

    public static void test3(Double num1, Double num2) {
        Compute compute = new Compute<Double>() {
            @Override
            public Double add(Double a, Double b) {
                return a + b;
            }

            @Override
            public Double sub(Double a, Double b) {
                return a - b;
            }

            @Override
            public Double mul(Double a, Double b) {
                return a * b;
            }

            @Override
            public Double div(Double a, Double b) {
                return a / b;
            }
        };
        System.out.println(compute.add(num1, num2));
        System.out.println(compute.sub(num1, num2));
        System.out.println(compute.mul(num1, num2));
        System.out.println(compute.div(num1, num2));
    }

}

interface Compute<T> {
    T add(T a, T b);

    T sub(T a, T b);

    T mul(T a, T b);

    T div(T a, T b);
}

class ComputeImp implements Compute<Double> {

    @Override
    public Double add(Double a, Double b) {
        return a + b;
    }

    @Override
    public Double sub(Double a, Double b) {
        return a - b;
    }

    @Override
    public Double mul(Double a, Double b) {
        return a * b;
    }

    @Override
    public Double div(Double a, Double b) {
        return a / b;
    }
}

class Computer {
    class CPU implements Compute<Double> {

        @Override
        public Double add(Double a, Double b) {
            return a + b;
        }

        @Override
        public Double sub(Double a, Double b) {
            return a - b;
        }

        @Override
        public Double mul(Double a, Double b) {
            return a * b;
        }

        @Override
        public Double div(Double a, Double b) {
            return a / b;
        }
    }
}
